<style scoped>
  @import "../../static/css/weui.css";
  @import "../../static/css/jquery-weui.min.css";
  .weui_cells:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 1px;
    border-top: 1px solid #D9D9D9;
    color: #D9D9D9;
  }
  .weui_cells_form .weui_cell_ft {
    transform: scale(0.7);
  }
</style>
<template>
  <div id="app-main">
    <form id="registerForm">
      <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
          <div class="weui_cell_hd"><img src="@/assets/mobile.png" style="width:30px;height:24px;vertical-align: middle;"/></div>
          <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input"  id="telphone"  name="loginname" type="number" v-model="mobile" pattern="[0-9]*" placeholder="输入手机号码"/>
          </div>
        </div>
        <div class="weui_cell ">
          <div class="weui_cell_hd"><img src="@/assets/mima.png" style="width:30px;height:24px;vertical-align: middle;"/></div>
          <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" id="password" name="password" type="password" v-model="pass" placeholder="输入登录密码"/>
          </div>
        </div>
      </div>
      <span id="errorSpan" style="display: inline-block;padding:5px 15px;"></span>
      <div class="weui_btn_area">
        <a class="weui_btn weui_btn_primary" @click="doLogin();" href="javascript:"  id="btn">登录</a>
      </div>
      <div align="center" style="margin-top:20px;">
        <a  href="javascript:;" @click="$router.push({name: 'signup'})" style="color:blue;font-size: 12px;">手机快速注册></a>
      </div>
      <div align="center" style="margin-top:20px;">
        <a  href="javascript:;" @click="$router.push({name: 'findpass'})" style="color:blue;font-size: 12px;">忘记密码?</a>
      </div>
    </form>
  </div>
</template>

<script type="text/babel">
  var wait = 60;//倒计时初始值
  export default {
    name: 'signin',
    data: () => ({
      mobile: '',
      pass: ''
    }),
    components: {
    },
    created() {
    },
    mounted() {
    },
    methods: {
      doLogin: function(){
        let that = this;
        var re = /^(1[3-9][0-9])\d{8}$/i;
        if(!re.test(this.mobile)){
          this.toastText('请输入正确的手机号')
          return false;
        }
        if(!this.pass){
          this.toastText('请输入密码')
          return false;
        }
        this.axios({
          method: 'post',
          url: '/prod-api/wechat/wechatLogin',
          params: {phone: that.mobile, pwd: that.pass}
        }).then(response => {
          if (response.data.code == 200) {
            localStorage.setItem('token', response.data.msg);
            this.getUser();
          }
          // else if (data.code == 1010) {
          //   this.toastText('您的用户密码太简单，请重新设置！');
          //   setTimeout(() => {
          //     this.$router.push({name: 'findpass'});
          //   }, 1500)
          // }
          else if (response.data.msg) {
            that.toastText(response.data.msg);
          } else {
            that.toastText("系统错误");
          }
        });
      },
      getUser: function () {
        this.axios({
          method: 'get',
          url: '/prod-api/getUserInfo'
        }).then(response => {
          if (response.data.code == 200) {
            this.resetSetItem('userName', response.data.data.userName);
            this.resetSetItem('userId', response.data.data.userId);
            this.resetSetItem('userGuid', response.data.data.guid);
            this.resetSetItem('userType', response.data.data.userType);
            this.toastSuccess('登录成功');
            setTimeout(() => {
              // location.href="/weixin/WechatCenter!index.action";
              this.$router.push({name: 'index'});
            }, 1000)
          }
        });
      }
    }
  };
</script>
